import time

from selenium import webdriver
from selenium.webdriver import Keys, ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service

if __name__ == '__main__':
    exe_path = "../driver/msedgedriver.exe"
    service = Service(executable_path=exe_path)
    brower = webdriver.Edge(service=service)
    brower.maximize_window()
    brower.get(url="https://www.jd.com")

    # 通过 id 查找元素
    input = brower.find_element(by=By.ID, value="key")
    # 模拟键盘，向输入框中输入内容
    input.send_keys("华为 P60")
    time.sleep(10)

    button = brower.find_element(by=By.CLASS_NAME, value="button")
    # 创建动作链
    action = ActionChains(driver=brower)
    # 设置动作链动作——移动到元素上
    action.move_to_element(button)
    # 设置动作链动作——点击元素
    action.click(button)
    # 执行设置的动作
    action.perform()

    time.sleep(10)
    brower.quit()